Render and assign materialsΒΆ

Render

The first thing we need to do is to create a RenderGraph. If there is no existing RenderGraph in the scene it will become the main one and therefore will drive the rendering of all passes. Otherwise, associate it to the render pass.

By default a RenderGraph comes with a minimalistic graph that performs some work. For the sake of clarity, we will erase the nodes inside and start from scratch.

Let's create the most basic graph that renders all the scene primitives into the layer of the pass.

  1. Create a new RenderGraph.
  2. Drill down in the NewRenderGraph, select all the nodes and delete them.
  3. Create a Tag node, a Layer node and an Output node and connect them as in the graph below.
  4. Select the Tag node and type 'All' in the Tag text box of a properties view.
  5. Select the Layer node and type 'All' in the Render Layer text box of a properties view.
  6. Render the image.

All the primitives are rendered in black since none of them have a material. Change the Alpha Mode in the Render view or the color in 'Render Settings > Debug > Default Surface Color' of the pass to better see the primitives.

This RenderGraph can be explained like this :

The Tag node selects all the primitives in the scene, since its Tag is 'All' and every scene graph node own the 'All' tag. The Tag node is connected to the Layer node which renders the selection in the Layer of the RenderPass, since its Render Layer is 'All' and the Layer has 'All' in its Layer Set. Finally the Layer node is connected to the Output node meaning that the graph will be evaluated and rendered.

Branches of the graph that are not directly or indirectly connected to the Output node will not be evaluated and rendered. Try to disconnect the Layer node from the Output node to convinced yourself of it.

It is possible for a graph to have several outputs. Practically, the scene will be duplicated at render time as many times as there are Output nodes in the scene. If it is not your intent to duplicate the scene, then you must not use multiple output nodes. Doing so increases the memory consumption and can causes strange artefacts.

Assign a material

Let's assign a material to all primitives that just returns the normal of the surface. This could perfectly be used in production for debugging a scene.

  1. Create a new material that returns the normal of the surface.
  2. Drill down into the previous NewRenderGraph.
  3. Create a Shader node and connect it as in the graph below.
  4. Select the Shader node and select NewMaterial in the Shader combo box.
  5. Render the image.

All the primitives are rendered using their normal as final color.

This RenderGraph can be explained like this :

The Tag node selects all the primitives in the scene, since its Tag is 'All' and every scene graph node own the 'All' tag. The Tag node is connected to the NewMaterial node, which assign the NewMaterial to the selection since its Mode is 'Set Material' and Shader is NewMaterial. The NewMaterial node is connected to the Layer node which renders the selection in the Layer of the RenderPass, since its Render Layer is 'All' and the Layer has 'All' in its Layer Set. Finally the Layer node is connected to the Output node meaning that the graph will be evaluated and rendered.

The place in the graph where the NewMaterial node has been inserted is completly meaningless. What really matters are the final attributes coming to the Output node. Nodes order is not important in a RenderGraph. Try to put the NewMaterial node after the Layer node to convinced yourself of it.

Assign a physically based material

Let's assign a physically based matte material to all primitives in the scene. In order the shading, lighting and shadowing to be physically correct the RenderGraph requires two new nodes. Those nodes are Set nodes whose goal is to perform association between a scene graph node and a string. The string is just a keyword used by lights in the scene to specify how they are going to interact with node surfaces : light or not a node, cast a shadow or not for a node, diffuse light or not on a node, etc. This approach of modeling primitives and lights interaction is very flexible since you will be able to tweak it in depth, depending your production needs.

  1. Use the Matte material of the library.
  2. Drill down into the previous NewRenderGraph.
  3. Create a Matte material node.
  4. Create two Set nodes and connect them as in the graph below.
  5. Select the left Set node and select Diffuse, Reflection and Refraction in the Set combo checkbox.
  6. Select the right Set node and select Lights and Shadows in the Set combo checkbox.
  7. Render the image.

All the primitives are rendered using a matte physically correct shading and all primitives are casting shadows according to the area light parameters.

This RenderGraph can be explained like this :

The Tag node selects all the primitives in the scene, since its Tag is 'All' and every scene graph node own the 'All' tag. The Tag node is connected to the Shader node, which assign the Matte material to the selection since its Mode is 'Set Material' and Shader is Matte. The Shader node is connected to the left Set node, which diffuse, reflect and refract light on the selection, since its Set is 'Diffuse', 'Reflection' and 'Refraction' and the Matte material has 'Diffuse', 'Reflection' and 'Refraction' in its Diffuse, Specular and Refraction Trace Set of its Microfacet node. The left Set node is connected to the right Set node which light the selection and make the selection cast shadow, since in its Set is 'Lights' and 'Shadows' and the AreaLight in the scene has 'Lights' and 'Shadows' in Light Set and Shadow Set. The right Set node is connected to the Layer node which renders the selection in the Layer of the RenderPass, since its Render Layer is 'All' and the Layer has 'All' in its Layer Set. Finally the Layer node is connected to the Output node meaning that the graph will be evaluated and rendered.

One Set node with the 'Diffuse', 'Reflection', 'Refraction', 'Lights' and 'Shadows' could have been used, but for the sake of clarity we prefer to split them in two separated nodes. That's also what is done in the minimalist graph that comes with a new RenderGraph, with two Set nodes named Trace and Lighting.